package controller;

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailController{  
	
    	public void SendEmail(String toAddress, String subject, String content) {  
        Properties props = new Properties();  
        props.setProperty("mail.smtp.host", "smtp.gmail.com");  
        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");  
        props.setProperty("mail.smtp.socketFactory.fallback", "false");  
        props.setProperty("mail.smtp.port", "465");  
        props.put("mail.smtp.auth", "true");  
        Session sendMailSession = Session.getInstance(props, null);  
  
        try {  
            Transport transport = sendMailSession.getTransport("smtp");  
            transport.connect("smtp.gmail.com", "issfacilitybookingsys@gmail.com",  
                    "Abc12345678");  
            Message newMessage = new MimeMessage(sendMailSession);  
  
            //Email subject   
            String mail_subject = subject;  
            newMessage.setSubject(mail_subject);  
  
            //Sender    
            String strFrom = "issfacilitybookingsys@gmail.com";  
            newMessage.setFrom(new InternetAddress(strFrom));  
            Address addressTo[] = { new InternetAddress(toAddress) };  
            newMessage.setRecipients(Message.RecipientType.TO, addressTo);  
  
            //Email Content  
            newMessage.setSentDate(new java.util.Date());  
            String mail_text = content;  
            newMessage.setText(mail_text);  
  
            newMessage.saveChanges();    
            transport.sendMessage(newMessage, newMessage.getRecipients(Message.RecipientType.TO)); //Send email    
            transport.close();  
            System.out.println("Sent OK");  
        } catch (Exception e) {  
            System.out.println(e);  
        }  
}
}